package dao.impl;

import dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import java.io.InputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserDaoImpl implements UserDao {
public List<User> findAll(){
    String resources ="mybatis-comfig.xml";
    SqlSession sqlSession = null;
     try{
         InputStream resourceAsStream = resources.class.getResourceAsStream(resources);
         SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
         SqlSession SqlSession = sqlSessionFactory.openSession();
         List<User> users = sqlSession.getMapper(UserDao.class).findAll();
         return users;
     }catch (Exception e){
         throw new RuntimeException(e);
     }finally {
         SqlSession.close();
     }
}
}
